import Vue from 'vue';
import Vuex from 'vuex';
import Cookie from 'js-cookie';

Vue.use(Vuex);

let state = {

  leftMenuStatus: Cookie.get('left_menu_status')==null?'open':Cookie.get('left_menu_status'),
  loginRememberPwd: Cookie.get('login_remember_pwd')==null?null:JSON.parse(Cookie.get('login_remember_pwd')),
  loginUserInfo: Cookie.get('login_user_info')==null?null:JSON.parse(Cookie.get('login_user_info')),
  userPermissions: [],
};
let actions = {};
let mutations = {
  setLoginRememberPwd:(state,val)=>{
    Cookie.set('login_remember_pwd', JSON.stringify(val), {expires: 30});
    state.loginRememberPwd = val;
  },

  setLoginUserInfo:(state,val)=>{
    Cookie.set('login_user_info', JSON.stringify(val), {expires: 30});
    state.loginUserInfo = val;
  },

  doToggleLeftMenu: (state) => {
    let status = state.leftMenuStatus == 'open' ? 'close' : 'open';

    state.leftMenuStatus = status;
    Cookie.set('left_menu_status', status, {expires: 30});
  },

  setUserPermissions: (state,val)=>{
    state.userPermissions = val;
  },

};

const store = new Vuex.Store({state, actions, mutations});

export default store;
